/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjtu.se1603.lh.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *数据库工具类
 * @author Administrator
 */
public class DBUtil {
    
    private static final String URL="jdbc:mysql://localhost:3306/petstore?zeroDateTimeBehavior=convertToNull";
    private static final String DB_USER="root";
    private static final String DB_PWD="18039005761";
    
    
   public static Connection getConnection(){
       Connection con=null;
       try {
           Class.forName("com.mysql.jdbc.Driver");
           con=DriverManager.getConnection(URL, DB_USER, DB_PWD);
       } catch (ClassNotFoundException ex) { 
           Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
       } catch (SQLException ex) {
            Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
       return  con;
   }
   
   public static void closeConnection(Connection con){
       if (con!=null) {
           try {
               con.close();
           } catch (SQLException ex) {
               Logger.getLogger(DBUtil.class.getName()).log(Level.SEVERE, null, ex);
           }
           
       }
   }
   
}
